package com.maple.soa.dao;

import com.maple.soa.pojo.DataSources;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

/**
 * @author lijian
 * @date 2020/7/5
 */
@Repository
public class DataConnection {
    @Autowired
    private DataSources dataSources;
    @Autowired
    @Qualifier("master")
    private DataSources master;
    @Autowired
    @Qualifier("slave")
    private DataSources slave;

    @Bean("master")
    @Primary
    public DataSources masterDataSources() {
        return new DataSources("com.mysql.cj.driver", "mysql://123.123.123.11:3306");
    }

    @Bean("slave")
    public DataSources slaveDataSources() {
        return new DataSources("com.Oracle.cj.driver", "mysql://22.22.22.22:2222");
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this);
    }
}
